"""Added Promocode model

Revision ID: 68201d8245e0
Revises: a51b0831a967
Create Date: 2023-10-17 17:40:40.754589

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "68201d8245e0"
down_revision = "a51b0831a967"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "promocode",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("amount", sa.Float(), nullable=False),
        sa.Column(
            "status",
            sa.Enum("active", "archive", name="promocodestatus"),
            server_default="active",
            nullable=True,
        ),
        sa.Column("limit", sa.Integer(), server_default="0", nullable=False),
        sa.Column("reusable", sa.Boolean(), server_default="0", nullable=False),
        sa.Column("uses_number", sa.Integer(), server_default="0", nullable=False),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_promocode")),
    )
    op.create_table(
        "promocodes_users",
        sa.Column("promocode_id", sa.Integer(), nullable=True),
        sa.Column("user_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ["promocode_id"],
            ["promocode.id"],
            name=op.f("fk_promocodes_users_promocode_id_promocode"),
        ),
        sa.ForeignKeyConstraint(["user_id"], ["user.id"], name=op.f("fk_promocodes_users_user_id_user")),
    )
    op.add_column("order", sa.Column("promocode_id", sa.Integer(), nullable=True))
    op.create_foreign_key(
        op.f("fk_order_promocode_id_promocode"),
        "order",
        "promocode",
        ["promocode_id"],
        ["id"],
    )
    op.alter_column(
        "payment_details",
        "payment_image_path",
        existing_type=sa.VARCHAR(),
        nullable=True,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "payment_details",
        "payment_image_path",
        existing_type=sa.VARCHAR(),
        nullable=False,
    )
    op.drop_constraint(op.f("fk_order_promocode_id_promocode"), "order", type_="foreignkey")
    op.drop_column("order", "promocode_id")
    op.drop_table("promocodes_users")
    op.drop_table("promocode")
    # ### end Alembic commands ###
